<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Http\Repositories\ArticlesRepository;
use App\Http\Repositories\CommentRepository;
use App\Http\Repositories\UserRepository;

class IndexController extends Controller
{
    protected $articlesRepository;
    protected $commentRepository;
    protected $userRepository;

    public function __construct(ArticlesRepository $articlesRepository,
                                CommentRepository $commentRepository,
                                UserRepository $userRepository)
    {
        $this->articlesRepository = $articlesRepository;
        $this->commentRepository = $commentRepository;
        $this->userRepository = $userRepository;
    }

    public function index()
    {
        // 统计数
        $user_counts = $this->userRepository->getUserCount();
        $comment_counts = $this->commentRepository->getCommentCount();
        $vote_count = 0;
        $article_counts = $this->articlesRepository->getCount();

        // 信息
        $system = [
            "php_version" => PHP_VERSION,
            "system_os" => php_uname('s') . '-' . php_uname('r'),
            "blog_version" => "0.10.0",
            "blog_name" => "SD"
        ];
        $hot_articles = $this->articlesRepository->getHotArticles();
        $new_comments = $this->commentRepository->newComment();
        return responseResult(
            compact('user_counts', 'comment_counts', 'vote_count', 'article_counts',
                'system', 'hot_articles', 'new_comments'),
            self::SUCCESS_CODE);
    }
}
